package edu.hubu.talentmanagementsystem.auth;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @author moonlan
 * date 2021/2/9 下午1:51
 */
@SuppressWarnings(value = "unused")
public class JwtToken extends AbstractAuthenticationToken {
    private final String token;

    public JwtToken(String token) {
        super(null);
        this.token = token;
        super.setAuthenticated(false);
    }

    public JwtToken(String token, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.token = token;
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return token;
    }

    @Override
    public Object getPrincipal() {
        return this.token;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        if (!isAuthenticated) {
            super.setAuthenticated(false);
        }
    }
}
